home *** CD-ROM | disk | FTP | other *** search
/ hornet.scene.org / hornet.scene.org FTP 11-25-2012.zip / hornet.scene.org FTP 11-25-2012 / code / 3d / trifill / envmap / envmap.doc < prev   
Text File  |  2012-06-16  |  4KB  |  83 lines

  1.  
  2.                          
  3.                           Enviroment Mapping Tutorial
  4.                               by Frenzy / TeSkO
  5.  ────────────────────────────────────────────────────────────────────────────
  6.  Hiya reader. This is a small tutorial to help people understand how simple
  7.  enviroment mapping really is :) I'm assuming you have expirence with 3d
  8.  graphics and have done Gouraud shading and texture mapping. Also, I'm
  9.  assuming you have knowledge of or have used fixed point maths namly 8.8
  10.  fixed point. If your answer is yes to all the above then this doc should
  11.  tell you what you need to know, otherwise I'd suggest you leech some other
  12.  tutors from ftp.cdrom.com or othersuch site..
  13.  
  14.  THE ENVIROMENT MAP:
  15.  ────────────────────────────────────────────────────────────────────────────
  16.  First things first, the enviroment map. This is just a texture map. It
  17.  can be any size but for simplicity I'm going to assume a 256x256 texture
  18.  map. This enviroment map can be anything you like. However, depending on
  19.  how your enviroment map looks depends on how your env mapping will look.
  20.  What I'm trying to say is this. If you have a good map your objects will
  21.  look a lot kewler. You can also simulate phong using env mapping just by
  22.  making an appropiate enviroment map. A sample enviroment map is given
  23.  called 'PHONG.PCX'. Its just a simple map that will make your objects
  24.  phong shaded. Once you have seen this you should get the basic idea on
  25.  what an enviroment map should look like. There is also one called
  26.  'METAL.PCX' which will make your objects look metalic/chrome. Looks very
  27.  nice. I got this from somewhere, dunno where. But it looks good and it
  28.  demonstrates what the enviroment maps should look like. BTW, this METAL.PCX
  29.  looks rather like a face.. How bizarre, I really would like to know where
  30.  it came from :-) 
  31.  
  32.  HOW TO ENVIROMENT MAP:
  33.  ────────────────────────────────────────────────────────────────────────────
  34.  Well, you've read the above and seen the .PCX files and you are still with
  35.  me. Good, here comes actual env mapping technique. 
  36.  
  37.  You have vertex normals for each vertex in your object right? Just like
  38.  in gouraud. Well, the way we use them is a bit different. In gouraud you
  39.  took the dot product of the light vector with each vertex normal. Well, in
  40.  env mapping you have to calculate the U,V coordinates so you can texture
  41.  map with them. Remember, env mapping is a straight texture map. The only
  42.  difference is the way you get your U,V coordinates. What you do is this:-
  43.  
  44.  You must have your vertex normals in 8.8 fixed point!!!
  45.  
  46.  For every vertex normal in your object compute its U,V coordinate by taking
  47.  the X and Y components and dividing by 2. This gets them in the range of
  48.  -128..128, then add 128 to that. That then gives you them in the range of
  49.  0..256 which just so happens to be the dimensions of your texture map :)
  50.  So, you have this:-
  51.  
  52.  U = (x / 2) + 128;
  53.  V = (y / 2) + 128;
  54.  
  55.  Now, once you have done that you can simply texture map as normal using
  56.  these U,V coordinates... Simple eh? Why, did you expect it to be hard??
  57.  
  58.  OPTIMIZATIONS:
  59.  ────────────────────────────────────────────────────────────────────────────
  60.  Of course, make your texture mapper fast. Also, you don't need to rotate
  61.  the vertex normals. This saves a lot of time. I won't go into this as you
  62.  might already know. If not then just ask. There is also another way to
  63.  find your U,V coordinates using spherical coordinates. However, this is
  64.  not necessary. 
  65.  
  66.  FINAL WORDS:
  67.  ────────────────────────────────────────────────────────────────────────────
  68.  Well, thats that done. A good 5mins read? if it didn't help then sorry
  69.  but it works for me.. If ya have any other questions then just ask. Your
  70.  surely have some.
  71.  
  72.  Oh yes, I threw together a small example called 'DEMO.EXE' to show you
  73.  what it should look like. Its crude but its only an example. Don't know
  74.  how fast it will be on your machine but on a dx4 120 it runs at 51 fps.
  75.  My env mapping is not fully optimised at the moment :(
  76.  
  77.  Byeeee
  78.  
  79.  Signed,
  80.  Paul aka Frenzy
  81.  EMAIL: p.adams@wlv.ac.uk
  82.  
  83.